# -*- encoding: utf-8 -*-
"""
@File    : principal_interest.py
@Time    : 2020/10/20 17:23
@Author  : lluyao
@Email   : lluyao61@163.com
@Software: PyCharm
"""
from decimal import Decimal

while True:
    money = input("请问您要存多少钱？")
    if money.isdigit():
        break
    else:
        print("您输入的数据不合法！")

while True:
    target = input("请问您到多少钱的时候取出来？")
    if target.isdigit():
        break
    else:
        print("您输入的数据不合法！")

money = Decimal(money)
target = Decimal(target)
year = 1
while money < target:
    interest = money*Decimal('0.05')
    print(f"第{year}年的本金是{money},利息是{interest}, 本息和为{money+interest}")
    # 计算下一年的本金，下一年的年份
    money = money+interest
    year += 1
print(f"到了第{year-1}年，能够实现目标")